function DateSelectGt(unique, dateTable, dayNames, sd, options) {
  this._unique = unique;
  this._dateTable = dateTable;
  this._dayNames = dayNames;
  this._sd = sd;
  
  this._timeTable = (options && options.timeTable) ? options.timeTable : null;
  this._input = (options && options.input) ? options.input : false;
  this._posRight = (options && options.posRight) ? options.posRight : null;
  this._posBelow = (options && options.posBelow) ? options.posBelow : null;
  this._selectedDate = (options && options.selectedDate) ? options.selectedDate : null;
  
  this._createElements();
}

DateSelectGt.prototype._createElements = function() {
  var tr, td, a, input;
  var sd = this._sd;
  
  this._dateTable.className = 'dateSelect';

  if (this._timeTable) {
    this._dateTable.style.borderTop = 'none';
  }
  

  if (this._input) {
    var pos = DOMUtils.findPos(this._input);

    this._dateTable.style.position = 'absolute';
    if (this._posRight) {
      this._dateTable.style.left = (pos[0] + this._input.offsetWidth + 5) + 'px';
      this._dateTable.style.top = (pos[1]) + 'px';
    } else if (this._posBelow) {
      this._dateTable.style.left = (pos[0]) + 'px';
      this._dateTable.style.top = (pos[1]) + (this._input.offsetHeight + 5) + 'px';
    }
  }

  tr = this._dateTable.insertRow(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td.setAttribute('colSpan', 1);
  td.className = 'dateSelectNav';
  td.appendChild(document.createTextNode('\u21d1'));
  td.id = this._unique + 'up';
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  
  tr = this._dateTable.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'dateSelectNav';
  td.appendChild(document.createTextNode('\u21d0'));
  td.id = this._unique + 'left';
  

  td = tr.insertCell(-1);
  td.setAttribute('colSpan', 5);
  td.className = 'dateSelectMonth';
  a = document.createElement('a');
  a.setAttribute('href', '#');
  td.id = this._unique + 'month';
  a.appendChild(document.createTextNode(''));
  td.appendChild(a);
  a.id = this._unique + 'aMonth';


  td = tr.insertCell(-1);
  td.className = 'dateSelectNav';
  td.appendChild(document.createTextNode('\u21d2'));
  td.id = this._unique + 'right';

  tr = this._dateTable.insertRow(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td.setAttribute('colSpan', 1);
  td.className = 'dateSelectNav';
  td.appendChild(document.createTextNode('\u21d3'));
  td.id = this._unique + 'down';
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  

  tr = this._dateTable.insertRow(-1);
  for (var i = 0; i < this._dayNames.length; i++) {
    this._days = tr.insertCell(-1);
    this._days.className = 'dateSelectDayLabel';
    this._days.appendChild(document.createTextNode(this._dayNames[i]));
  }


  tr = this._dateTable.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'dateSelectCurrentLabel';
  td.setAttribute('colSpan', 7);
  td.id = this._unique + 'currentSelected';
  td.appendChild(document.createTextNode(''));

  tr = this._dateTable.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'dateSelectNav';
  td.appendChild(document.createTextNode('Clear'));
  td.id = this._unique + 'clear';
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  td = tr.insertCell(-1);
  
  var today = new Date();
  var first = new Date(sd.year, sd.month - 1, 1);
  var end = new Date(sd.year, sd.month, -1);
  if (sd.date > end.getDate()) {
    sd.date = end.getDate() + 1;
  }

  var i, j = 4;
  for (i = 0, il = end.getDate() + first.getDay() + 1; i < il; i++) {
    if ((i % 7) == 0) {
      tr = this._dateTable.insertRow(j++);
    }
    td = tr.insertCell(-1);
    var num = (i - first.getDay() + 1);
    if (i >= first.getDay()) {
      
      if (this._start || this._end) {
        if ((!this._start || SimpleDate.toStamp(SimpleDate.create(first.getFullYear(), (first.getMonth() + 1), num)) >= this._start) && (!this._end || SimpleDate.toStamp(SimpleDate.create(first.getFullYear(), (first.getMonth() + 1), num)) <= this._end)) {
          td.className = 'dateSelectDay'; 
          td.id = this._unique + i + 'td1';
          td.appendChild(document.createTextNode(num));
        } else {
          td.style.textAlign = 'center';
          td.appendChild(document.createTextNode(num));
        }
      } else {
        td.className = 'dateSelectDay';
        td.id = this._unique + i + 'td2';
        td.appendChild(document.createTextNode(num));
      }
      
      
      if ((num == today.getDate()) && (first.getMonth() == today.getMonth()) && (first.getFullYear() == today.getFullYear())) {
        td._today = true;
        if (this._start || this._end) {
          if ((!this._start || SimpleDate.toStamp(SimpleDate.create(first.getFullYear(), (first.getMonth() + 1), num)) >= this._start) && (!this._end || SimpleDate.toStamp(SimpleDate.create(first.getFullYear(), (first.getMonth() + 1), num)) <= this._end)) {
            td.className = 'dateSelectToday';
          } else {
            td.style.textAlign = 'center';
          }
        } else {
          td.className = 'dateSelectToday';
        }
      }
      if ((this._selectedDate !== null) && (first.getFullYear() == this._selectedDate.year) && ((first.getMonth() + 1) == this._selectedDate.month) && (num == this._selectedDate.date)) {
        this._lastSelectedNode = td;
        if (this._start || this._end) {
          if ((!this._start || SimpleDate.toStamp(SimpleDate.create(first.getFullYear(), (first.getMonth() + 1), num)) >= this._start) && (!this._end || SimpleDate.toStamp(SimpleDate.create(first.getFullYear(), (first.getMonth() + 1), num)) <= this._end)) {
            td.className = 'dateSelectSelected';
          } else {
            td.style.textAlign = 'center';
          }
        } else {
          td.className = 'dateSelectSelected';
        }
      }
    } else {
      
      td.className = 'dateSelectDayEmpty';
      td.appendChild(document.createTextNode(''));
    }
  }

  
  while ((i % 7) != 0) {
    td = tr.insertCell(-1);
    td.className = 'dateSelectDayEmpty';
    td.appendChild(document.createTextNode(''));
    i++;
  }
};